﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;

namespace RexToy.UI.WinForm.Pmlx
{
    class AutomaticLocator : IPmlxFileLocator
    {
        private IPmlxFileLocator _embed;
        private IPmlxFileLocator _isolate;
        public AutomaticLocator()
        {
            _embed = new EmbedLocator();
            _isolate = new IsolateLocator();
        }

        public PmlxDoc ReadPmlxFile(UserControl uc)
        {
            if (_embed.ExistPmlxFile(uc))
                return _embed.ReadPmlxFile(uc);
            if (_isolate.ExistPmlxFile(uc))
                return _isolate.ReadPmlxFile(uc);
            return null;
        }

        public PmlxDoc ReadPmlxFile(Form f)
        {
            if (_embed.ExistPmlxFile(f))
                return _embed.ReadPmlxFile(f);
            if (_isolate.ExistPmlxFile(f))
                return _isolate.ReadPmlxFile(f);
            return null;
        }

        public bool ExistPmlxFile(UserControl uc)
        {
            return _embed.ExistPmlxFile(uc) || _isolate.ExistPmlxFile(uc);
        }

        public bool ExistPmlxFile(Form f)
        {
            return _embed.ExistPmlxFile(f) || _isolate.ExistPmlxFile(f);
        }
    }
}
